﻿Imports MySql.Data.MySqlClient

Public Class frmAddProduct
  Private m_CurCategoryID As Integer = 0

	Private Sub btnAddCategory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCategory.Click
		Dim fProductCategory As frmProductCategoryManage = New frmProductCategoryManage()
		fProductCategory.ShowDialog(Me)
    If (fProductCategory.DialogResult = Windows.Forms.DialogResult.OK) Then      
      txtCategory.Text = fProductCategory.GetCurrentProductCateName().Trim()
      m_CurCategoryID = fProductCategory.GetCurentProductCateID()
      If txtCategory.Text.Equals("") Or m_CurCategoryID = 0 Then
        MessageBox.Show("Bạn phải chọn một cho loại sản phẩm.", "Loại Sản Phẩm", MessageBoxButtons.OK, MessageBoxIcon.Error)
        txtCategory.Focus()
      End If
    End If
	End Sub

	Public Function AddProduct() As Boolean
		Try
			Dim dbAccess As DataBaseAccess = New DataBaseAccess
      Dim SQLString As String = "SELECT * FROM tbl_restorationdetail"
			Dim dtTable = dbAccess.GetDataTable(SQLString)
			Dim dtRow = dtTable.NewRow
			SetProductData(dtRow)
			dtTable.Rows.Add(dtRow)
			Return dbAccess.UpdateDataTable(SQLString, dtTable)
    Catch ex As Exception
      Throw New Exception(" Can not insert material record ")
      Return False
		End Try
	End Function

	Private Sub SetProductData(ByRef drow As DataRow)
		drow("Name") = txtName.Text.Trim()
		'drow("CategoryID") = "01" 'm_CurCategoryID
		'		drow("CreateDate") = dtpCreateDate.Value.Year.ToString()
		'		drow("CreateMonth") = dtpCreateDate.Value.Month.ToString()
		'		drow("CreateYear") = dtpCreateDate.Value.Day.ToString()
		'		drow("EndDate") = dtpEndDate.Value.Year.ToString()
		'		drow("EndMonth") = dtpEndDate.Value.Month.ToString()
		'		drow("EndYear") = dtpEndDate.Value.Day.ToString()
		'		drow("ImportPrice") = Convert.ToDouble(IIf(String.IsNullOrEmpty(txtPrice.Text.Trim()), 0, txtPrice.Text.Trim()))
		'		drow("Unit") = cmbUnit.Text.Trim()
		'		drow("Quality") = txtQuality.Text.Trim()
		'		drow("MaterialID") = txtMaterialID.Text.Trim()
		'		drow("Comments") = txtComments.Text.Trim()
	End Sub

	Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
		AddProduct()
	End Sub
End Class